﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DcsGauges.Gui.Rendering;
using DcsGauges.Gui.Gauges.ValueConverters;
using DcsGauges.DataStructures;
using DcsGauges.Gui.Gauges.Interfaces;
using DcsGauges.Shared.DataStructures;
using Microsoft.Xna.Framework;

namespace DcsGauges.Gui.Gauges.Concrete
{
    class EngineTemperatureGauge : CircularGaugeWithSubRotator
    {
        const float MIN_INITIAL_ROTATION       = 122.0f;

        private static readonly IGaugeValueConverter<float> tempToUni = new LinearConverter(new InOutMapping(0.0f, 0.0f), new InOutMapping(1100.0f, 1.0f));

        //32
        public EngineTemperatureGauge(GuiRenderableBase parent, URect area, DcsProperty temperatureUnitProp, DcsProperty temperatureTenthProp) 
            : base(parent, area, 
                    temperatureUnitProp,
                    temperatureTenthProp,
                    new InterpolatingConverter(
                        new List<InOutMapping>()
                        {
                            new InOutMapping(tempToUni.Convert(100.0f), MathEx.Deg2Rad(122.0f)), // all below 100°C is displayed as 100
                            new InOutMapping(tempToUni.Convert(300.0f), MathEx.Deg2Rad(175.0f)),
                            new InOutMapping(tempToUni.Convert(660.0f), MathEx.Deg2Rad(270.0f)),
                            new InOutMapping(tempToUni.Convert(1000.0f), MathEx.Deg2Rad(357.0f)),
                            new InOutMapping(tempToUni.Convert(1100.0f), MathEx.Deg2Rad(360.0f + 32.0f)), //all above 1100°C is displayed as 1100
                        }),
                    new LinearConverter(new InOutMapping(0.0f, MathEx.Deg2Rad(0.0f)), new InOutMapping(1.0f, MathEx.Deg2Rad(360.0f))),
                    TextureManager.GetTexture("Textures/Gauges/Needles/EngineGaugesSub"),
                    TextureManager.GetTexture("Textures/Gauges/Backgrounds/EngineTemperature"), 
                    TextureManager.GetTexture("Textures/Gauges/Needles/EngineGaugesNeedle"), 
                    URect.CalcFromCenter(new Vector2(0.786f, 0.472f), new Vector2(0.2f, 0.2f)))

        {

        }
    }
}
